#ifndef _AVR_EXTERNAL_INTERRUPT_H_
#define _AVR_EXTERNAL_INTERRUPT_H_

#include "../../Component.h"
#include<avr/io.h>
#include<avr/interrupt.h>
#include "../../../bit/bit.h"

namespace Hardware
{
namespace Avr
{

	typedef struct EXTERNAL_INTERRUPT_CONFIG
	{
		unsigned char interruptSense1 : 2;
		unsigned char interruptSense0 : 2;
		unsigned char interruptSense2 : 1;
		unsigned char interruptEnable1 : 1;
		unsigned char interruptEnable0 : 1;
		unsigned char interruptEnable2 : 1;
		
	} ExternalInterruptConfig;

	typedef struct EXTERNAL_INTERRUPT_DATA
	{
		unsigned char interruptFlag1 : 1;
		unsigned char interruptFlag0 : 1;
		unsigned char interruptFlag2 : 1;
	} ExternalInterruptData;

	class ExternalInterrupt : public Component<ExternalInterruptConfig,
						 ExternalInterruptData>
	{
		public :
		enum InterruptSenseControl
		{
			LowInterrupt = 0x00,
			AnyChangeInterrupt = 0x01,
			FallingInterrupt = 0x02,
			RisingInterrupt = 0x03
		};
		enum InterruptSense2Control
		{
			FallingOnINT2 = 0x00,
			RisingOnINT2 = 0x01
		};

		ExternalInterrupt(){}
		ExternalInterrupt(ExternalInterruptConfig c){configuration=c;}
		void config()
		{
			//set interrupt sense 1
			MCUCR = (MCUCR & 0xF3) | (configuration.interruptSense1<<2);
			//set interrupt sense 0.
			MCUCR = (MCUCR & 0xFC) | (configuration.interruptSense0);
			//set interrupt sense 2.
			MCUCR = SetBit(MCUCR, ISC2, configuration.interruptSense2);
			//set interrupt sense 1 enable
			GICR = SetBit(GICR, INT1, configuration.interruptEnable1);
			//set interrupt sense 0 enable
			GICR = SetBit(GICR, INT0, configuration.interruptEnable0);
			//set interrupt sense 2 enable
			GICR = SetBit(GICR, INT2, configuration.interruptEnable2);
			
		}
		void run(){}
	};
}
}




#endif
